home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / dos / diverses / cexpress / printer / prtfrwd.asm < prev    next >
Encoding:
Assembly Source File  |  1989-05-03  |  6.0 KB  |  209 lines

  1. ;void  prt_forward(strg,field_size,printer_codes)
  2. ;  char  *strg,*printer_codes;
  3. ;  int   field_size;
  4.  
  5.     EXTRN  _memory_model:byte
  6.     EXTRN  _error_code:byte
  7.     EXTRN  _time_out:byte
  8.  
  9. _TEXT    SEGMENT BYTE PUBLIC 'CODE'
  10.     ASSUME  CS:_TEXT
  11.     PUBLIC  _prt_forward
  12. _prt_forward proc near
  13.     push bp            ;
  14.     mov  bp,sp        ;
  15.     push di            ;
  16.     push si            ;
  17.     push ds            ;
  18.     cmp  _memory_model,0    ;near or far?
  19.     jle  begin        ;jump if near
  20.     inc  bp            ;else add 2 to BP
  21.     inc  bp            ;
  22. begin:    jmp  short A1
  23. keep_count   dw ?
  24. keep_target  dw ?
  25. remaining_spc dw ?
  26. field_size   db ?
  27. codes_seg    dw ?
  28. codes_ofs    dw ?
  29. A1:    mov  ah,1        ;BIOS func to init prtr
  30.     sub  dx,dx        ;choose LPT1
  31.     int  17h        ;initialize the prtr port
  32.     sub  ax,ax        ;clear AX
  33.     mov  es,ax        ;point ES to 0000:0000
  34.     mov  dx,es:[408h]    ;get LPT1 base address
  35.     mov  _error_code,1    ;1 = printer error
  36.     mov  al,_time_out    ;get _time_out seconds
  37.     cmp  _memory_model,2    ;data near or far?
  38.     jb   B1            ;jump if near    
  39.     lds  si,dword ptr[bp+4] ;DS:SI pts to Strg
  40.     mov  bh,[bp+8]        ;field size
  41.     les  di,dword ptr[bp+10] ;ES:DI pts to PrinterCodes
  42.     jmp  short B2        ;
  43. B1:    mov  si,[bp+4]        ;NEAR case
  44.     mov  bh,[bp+6]        ;
  45.     mov  di,[bp+8]        ;
  46.     push ds            ;
  47.     pop  es            ;
  48. B2:    mov  cs:field_size,bh    ;store parameters for later
  49.     mov  cs:codes_seg,es    ;
  50.     mov  cs:codes_ofs,di    ;
  51.     or   al,al        ;don't allow 0 seconds in time out
  52.     jnz  C1            ;
  53.     mov  al,3        ;default to 3 seconds
  54. C1:    mov  cl,18        ;18 ticks per second
  55.     mul  cl            ;
  56.     mov  cs:keep_count,ax    ;save count
  57.     sub  cx,cx        ;clear CX
  58.     cmp  byte ptr[si],0    ;test for null input string
  59.     jne  C2            ;jump if not null
  60.     sub  ax,ax        ;
  61.     mov  al,bh        ;field size in AX
  62.     mov  cs:remaining_spc,ax ;write that many spaces
  63.     jmp  R1            ;go write spaces
  64. C2:    push si            ;go count number code chars in Strg
  65.     sub  cx,cx        ;also count string length
  66.     sub  al,al        ;AL counts control codes
  67. D1:    mov  ah,[si]        ;get char from Strg
  68.     or   ah,ah        ;terminating null yet?
  69.     jz   E2            ;quit loop if so
  70.     cmp  ah,128        ;test lower end of range
  71.     jb   E1            ;jump if below
  72.     cmp  ah,159        ;test upper limit
  73.     ja   E1            ;jump if above
  74.     inc  al            ;else inc code counter
  75. E1:    inc  si            ;forward string pointer
  76.     inc  cx            ;inc string length counter
  77.     jmp  short D1        ;go check next char
  78. E2:    pop  si            ;
  79.     sub  bx,bx        ;
  80.     mov  bl,cs:field_size    ;field size in BX
  81.     sub  bx,cx        ;minus string length
  82.     add  bl,al        ;adjust for code chars
  83.     or   bl,bl        ;test for zero spaces after string
  84.     jnle J1            ;jump if string is shorter than field
  85.     sub  bx,bx        ;commence code for field shorter than strg
  86.     sub  cx,cx        ;
  87.     mov  bl,cs:field_size    ;number chars to print
  88.     push si            ;figure how many chars to print
  89. H1:    mov  al,[si]        ;get a character
  90.     cmp  al,128        ;test if control code
  91.     jb   I1            ;jump if below range
  92.     cmp  al,159        ;test if above
  93.     ja   I1            ;jump if above
  94.     inc  si            ;
  95.     inc  cx            ;
  96.     jmp  short H1        ;        
  97. I1:    inc  si            ;
  98.     inc  cx            ;
  99.     dec  bl            ;dec field counter
  100.     jnz  H1            ;
  101.     pop  si            ;
  102.     mov  bx,0        ;print no trailing spaces
  103. J1:    mov  cs:remaining_spc,bx ;save number spaces to write
  104. K1:    mov  al,[si]        ;get a character
  105.     cmp  al,128        ;test if control code
  106.     jb   P1            ;jump if below range
  107.     cmp  al,159        ;test if above
  108.     ja   P1            ;jump if above
  109.     push cx            ;save Strg len ctr
  110.     push si            ;save Strg pos ptr
  111.     push ax            ;point ES:DI to PrinterCodes
  112.     mov  ax,cs:codes_seg    ;
  113.     mov  es,ax        ;
  114.     mov  di,cs:codes_ofs    ;
  115.     pop  ax            ;
  116.     sub  al,128        ;count codes from 0
  117.     mov  cl,6        ;times six bytes
  118.     mul  cl            ;offset in PrinterCodes
  119.     add  di,ax        ;SI pts to code sequence
  120.     sub  cx,cx        ;clear CX
  121.     mov  cl,es:[di]        ;get string descriptor
  122.     jcxz O1            ;quit loop if null
  123. L1:    inc  di            ;forward ptr
  124.     mov  al,[di]        ;get code character
  125.     call Writeit        ;
  126.     or   ah,ah        ;printer error?
  127.     jnz  N1            ;continue if not
  128.     pop  si            ;restore Strg pos ptr
  129.     pop  cx            ;restore Strg len ctr
  130. M1:    jmp  short U1        ;go quit routine
  131. N1:    loop L1            ;go do next
  132. O1:    pop  si            ;restore Strg pos ptr
  133.     pop  cx            ;restore Strg len ctr
  134.     jmp  short Q1        ;go get next char in Strg
  135. P1:    call Writeit        ;
  136.     or   ah,ah        ;proc returned error?
  137.     jz   U1            ;quit if so
  138. Q1:    inc  si            ;forward Strg ptr
  139.     dec  cl            ;dec Strg len ctr
  140.     jnz  K1            ;loop till finished
  141. R1:    mov  al,' '        ;fill char to AL
  142.     mov  cx,cs:remaining_spc ;right border length
  143.     jcxz T1            ;quit if no right border
  144.     mov  ch,al        ;copy back to CH
  145. S1:    mov  al,ch        ;fill char to AL
  146.     call Writeit        ;
  147.     or   ah,ah        ;check for printer error
  148.     jz   U1            ;quit if error
  149.     dec  cl            ;dec border len counter
  150.     jnz  S1            ;loop till finished
  151. T1:    pop  ds            ;
  152.     dec  _error_code    ;0 = no error
  153.     jmp  short V1        ;
  154. U1:    pop  ds            ;
  155. V1:    pop  si            ;
  156.     pop  di            ;
  157.     pop  bp            ;
  158.     cmp  _memory_model,0    ;quit
  159.     jle  quit        ;
  160.     db   0CBh        ;RET far
  161. quit:    ret            ;RET near
  162. Writeit    PROC
  163.     out  dx,al        ;send to output data register
  164.     inc  dx            ;forward to status register
  165.     push cx            ;save string counter
  166.     call GetBiosCount    ;get timer reading
  167.     mov  bx,cx        ;make copy
  168.     add  cx,cs:keep_count    ;add delay count
  169.     cmp  bx,cx        ;if timer doesn't turn over...
  170.     jb   W1            ;go ahead
  171.     mov  cx,cs:keep_count    ;otherwise, extend delay
  172. W1:    mov  cs:keep_target,cx    ;save target count on stack
  173. Wait:    in   al,dx        ;get status value
  174.     test al,8        ;test for printer error
  175.     jz   Error        ;
  176.     test al,80h        ;test for Printer Ready
  177.     jnz  Ready        ;jump if ready
  178. Error:    call GetBiosCount    ;
  179.     cmp  cx,cs:keep_target    ;compare to target
  180.     jb   Wait        ;    
  181.     mov  bl,1        ;1 = error
  182.     pop  cx            ;restore string counter
  183.     mov  ah,0        ;return code for failure
  184.     jmp  short X1        ;return
  185. Ready:    pop  cx            ;restore string counter
  186.     inc  dx            ; output control register
  187.     mov  al,13        ;bits for strobe signal
  188.     out  dx,al        ;send the signal
  189.     dec  al            ;change to strobe OFF
  190.     out  dx,al        ;send the signal
  191.     dec  dx            ;point back to
  192.     dec  dx            ;  base address
  193.     mov  ah,1        ;return code for success
  194. X1:    ret              ;
  195. Writeit    endp
  196. GetBIOSCount PROC
  197.     push dx            ;return value in CX:DX
  198.     push ax            ;
  199.     sub  ah,ah        ;function number
  200.     int  1ah        ;get timer count
  201.     mov  cx,dx        ;low word in CX
  202.     pop  ax            ;
  203.     pop  dx
  204.     ret
  205. GetBIOSCount endp
  206. _prt_forward endp
  207. _TEXT    ENDS
  208.     END
  209.